local x=2
local z=2*`x'
local zz=3*`x'


gen chngsalepricefull=chngsaleprice
replace chngcontract=. if common2!=1
replace chngsaleprice=. if common2!=1


gen coeff=.
gen seup=.
gen selow=.

newey chngcontract  F.surprise  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract _I* ,lag(4)
replace coeff=_b[F.surprise] in 1
replace seup=_b[F.surprise]+1.645*_se[F.surprise] in 1
replace selow=_b[F.surprise]-1.645*_se[F.surprise] in 1

newey chngcontract  surprise  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract _I* ,lag(4)
replace coeff=_b[surprise] in 2
replace seup=_b[surprise]+1.645*_se[surprise] in 2
replace selow=_b[surprise]-1.645*_se[surprise] in 2

local k=3
forvalues j=1/6{
newey chngcontract  L`j'.surprise  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.surprise] in `k'
replace seup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace selow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}


forvalues j=7/8{
newey chngcontract  L`j'.surprise  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.surprise] in `k'
replace seup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace selow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}
forvalues j=9/10{
newey chngcontract  L`j'.surprise  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract L10.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.surprise] in `k'
replace seup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace selow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}

forvalues j=11/12{
newey chngcontract  L`j'.surprise  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract L10.chngcontract L12.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.surprise] in `k'
replace seup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace selow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}

forvalues j=13/14{
newey chngcontract  L`j'.surprise  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract L10.chngcontract L12.chngcontract L14.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.surprise] in `k'
replace seup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace selow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}

forvalues j=15/16{
newey chngcontract  L`j'.surprise  L`x'.chngcontract L`z'.chngcontract L`zz'.chngcontract L8.chngcontract L10.chngcontract L12.chngcontract L14.chngcontract L16.chngcontract _I* ,lag(4)
replace coeff=_b[L`j'.surprise] in `k'
replace seup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace selow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}









gen spcoeff=.
gen spseup=.
gen spselow=.

newey chngsaleprice  F.surprise  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[F.surprise] in 1
replace spseup=_b[F.surprise]+1.645*_se[F.surprise] in 1
replace spselow=_b[F.surprise]-1.645*_se[F.surprise] in 1

newey chngsaleprice  surprise  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[surprise] in 2
replace spseup=_b[surprise]+1.645*_se[surprise] in 2
replace spselow=_b[surprise]-1.645*_se[surprise] in 2

local k=3
forvalues j=1/6{
newey chngsaleprice  L`j'.surprise  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.surprise] in `k'
replace spseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}


forvalues j=7/8{
newey chngsaleprice  L`j'.surprise  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.surprise] in `k'
replace spseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}
forvalues j=9/10{
newey chngsaleprice  L`j'.surprise  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice L10.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.surprise] in `k'
replace spseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}

forvalues j=11/12{
newey chngsaleprice  L`j'.surprise  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice L10.chngsaleprice L12.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.surprise] in `k'
replace spseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}

forvalues j=13/14{
newey chngsaleprice  L`j'.surprise  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice L10.chngsaleprice L12.chngsaleprice L14.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.surprise] in `k'
replace spseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}

forvalues j=15/16{
newey chngsaleprice  L`j'.surprise  L`x'.chngsaleprice L`z'.chngsaleprice L`zz'.chngsaleprice L8.chngsaleprice L10.chngsaleprice L12.chngsaleprice L14.chngsaleprice L16.chngsaleprice _I* ,lag(4)
replace spcoeff=_b[L`j'.surprise] in `k'
replace spseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}




gen spfullcoeff=.
gen spfullseup=.
gen spfullselow=.

newey chngsalepricefull  F.surprise  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[F.surprise] in 1
replace spfullseup=_b[F.surprise]+1.645*_se[F.surprise] in 1
replace spfullselow=_b[F.surprise]-1.645*_se[F.surprise] in 1

newey chngsalepricefull  surprise  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[surprise] in 2
replace spfullseup=_b[surprise]+1.645*_se[surprise] in 2
replace spfullselow=_b[surprise]-1.645*_se[surprise] in 2

local k=3
forvalues j=1/6{
newey chngsalepricefull  L`j'.surprise  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.surprise] in `k'
replace spfullseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spfullselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}


forvalues j=7/8{
newey chngsalepricefull  L`j'.surprise  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.surprise] in `k'
replace spfullseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spfullselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}
forvalues j=9/10{
newey chngsalepricefull  L`j'.surprise  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull L10.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.surprise] in `k'
replace spfullseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spfullselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}

forvalues j=11/12{
newey chngsalepricefull  L`j'.surprise  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull L10.chngsalepricefull L12.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.surprise] in `k'
replace spfullseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spfullselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}

forvalues j=13/14{
newey chngsalepricefull  L`j'.surprise  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull L10.chngsalepricefull L12.chngsalepricefull L14.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.surprise] in `k'
replace spfullseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spfullselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}

forvalues j=15/16{
newey chngsalepricefull  L`j'.surprise  L`x'.chngsalepricefull L`z'.chngsalepricefull L`zz'.chngsalepricefull L8.chngsalepricefull L10.chngsalepricefull L12.chngsalepricefull L14.chngsalepricefull L16.chngsalepricefull _I* ,lag(4)
replace spfullcoeff=_b[L`j'.surprise] in `k'
replace spfullseup=_b[L`j'.surprise]+1.645*_se[L`j'.surprise] in `k'
replace spfullselow=_b[L`j'.surprise]-1.645*_se[L`j'.surprise] in `k'
local k=`k'+1
}


gen index=_n-2


line coeff seup selow index if coeff!=., lcolor(black black black) lpattern(l - - ) xlabel(-1 (1) 16) title("Contract-Dated Index") saving(contract.gph,replace) ylabel(-0.15 (.1) 0.25) yline(0,lcolor(black)) legend(off) xtitle("Number of Lags (in weeks)")
line spcoeff spseup spselow index if coeff!=., lcolor(black black black) lpattern(l - - ) xlabel(-1 (1) 16) title("Closing-Dated Index")  saving(saleprice.gph,replace) ylabel(-0.15 (.1) 0.25) yline(0,lcolor(black)) legend(off)  xtitle("Number of Lags (in weeks)")
line spfullcoeff spfullseup spfullselow index if coeff!=., lcolor(black black black) lpattern(l - - ) xlabel(-1 (1) 16) title("Closing-Dated Index (Full Sample)")  saving(salepricefull.gph,replace) ylabel(-0.15 (.1) 0.25) yline(0,lcolor(black)) legend(off)  xtitle("Number of Lags (in weeks)")
graph combine contract.gph saleprice.gph salepricefull.gph,rows(2)
graph export irf_surprise.ps,replace logo(off)
!ps2pdf irf_surprise.ps irf_surprise.pdf
